package com.jinhongone.pattern.behavior.iterator;

/**
 * @author jinho
 * @className Test
 * @description 测试类
 * @date 2025/4/17 9:06
 */
public class Test {

    public static void main(String[] args) {
        //创建聚合对象
        StudentAggregateImpl studentAggregate = new StudentAggregateImpl();
        //创建元素对象
        Student stu1 = new Student("张三","001");
        Student stu2 = new Student("李四","002");
        Student stu3 = new Student("王五","003");
        //将元素添加到聚合中
        studentAggregate.addStudent(stu1);
        studentAggregate.addStudent(stu2);
        studentAggregate.addStudent(stu3);
        //根据聚合对象获取迭代器进行迭代
        StudentIterator studentIterator = studentAggregate.getStudentIterator();
        while(studentIterator.hasNext()){
            System.out.println(studentIterator.next());
        }
    }
}
